<?php

class Admin_Model_Rolesoption extends Zend_Db_Table_Abstract{
    protected $_name = 'roles_option';
    public function getRoleIdData($roleId){
        $query = $this->select()
                    ->from($this->_name)
                    ->where('roleId = ?', $roleId);
        return $this->fetchRow($query);
    }
    public function getDataByUserId($userId){
        $query = $this->select()
                    ->setIntegrityCheck(false)
                    ->from(array('o'=>'roles_option'), array('o.roleId', 'o.views'))
                    ->where('o.roleId IN (SELECT u.roleId FROM users_roles u WHERE u.userId = '.$userId.')');
        return $this->fetchAll($query);
    }
    public function addData($roleId, $views = '', $resourceId = 1)
    {
        $data = array('roleId' => $roleId, 'views'=> $views, 'resourceId' => $resourceId);
        return $this->insert($data);
    }
    public function editData($roleId, $views = '', $resourceId = 1)
    {
        $data = array('views' => $views, 'resourceId' => $resourceId);
        return $this->update($data, 'roleId = '.$roleId);
    }
    public function deleteDataByRoleId($id)
    {
        $this->delete("roleId=".(int)$id);
    }
}